<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <!-- 对象类型的值需要使用this.$set(Vue.set)或者this.$delete(Vue.delete) -->
        <div>{{person.name}}</div>
        <div>{{person.age}}</div>
        <div>{{person.sex}}</div>
        <button @click="person.age++">加一</button>
        <button @click="addAttr">性别</button>
        <button @click="deleteAttr">名字</button>
    </div>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    person: {
                        name: '文水洪',
                        age: 21,
                        sex: '女'
                    }
                }
            },
            methods: {
                deleteAttr() {
                    this.$delete(this.person, 'name')
                },
                addAttr() {
                    this.$set(this.person, "sex", '男')
                }
            }
        })
    </script>
</body>

</html>